<template>
  <div>
     <el-container>
  <el-header>
      <h1>后台管理</h1>
    <el-button type="primary" @click="goTo" size="mini">退出</el-button>
  </el-header>
  <el-container>
        <el-aside :width="isCollapse?'64px':'200px'" class="el-aside">
             <h1 @click="isCollapse=!isCollapse">|&emsp;|&emsp;|</h1>
      <el-menu
        default-active="2"
        class="el-menu-vertical-demo"
        background-color="#545c64"
        text-color="#fff"
        router
         :collapse="isCollapse"
        active-text-color="#ffd04b"
      >
        <el-submenu :index="item.id+''" v-for="(item,index) in leftSide" :key="index">
          <template slot="title">
            <i class="el-icon-menu"></i>
            <span>{{item.authName}}</span>
          </template>

          <el-menu-item :index="'/'+ite.path" v-for="(ite,ind) in item.children" :key="ind">
            <i class="el-icon-document"></i>
            <span>{{ite.authName}}</span>
          </el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-main>
      <keep-alive>
        <router-view></router-view>
      </keep-alive>
    </el-main>
  </el-container>
</el-container>

  </div>
</template>

<script>
import { getMenus } from "../api/api";
import {fn} from '../utils/index'; //生成列表结构路由方法
export default {
  data() {
    return {
      leftSide: [],
      isCollapse:false,
    };
  },
  created () {
    this.getSide();
  },
  methods: {
    goTo(){
      localStorage.removeItem("token")
      this.$router.push("/loginName")
    },
    async getSide() {
      let res = await getMenus();
      console.log(res, "res");
      this.leftSide=res.data
      localStorage.setItem("menuList",JSON.stringify(res.data))

           //传进去树状路由表-调用递归方法返回列表结构
          let newArr=fn(res.data)
          console.log('路由列表结构1',newArr);
          newArr.forEach(item=>{
              this.$router.addRoute('HomeView',item)
          })
    },
  },
};
</script>

<style scoped>

  .el-header, .el-footer {
    background-color: #B3C0D1;
    color: #333;
    /* text-align: center;
    line-height: 60px; */
    display: block;
    display: flex;
    justify-content: space-around;
    align-items: center;
  }
  

  
  .el-main {
    background-color: #E9EEF3;
    color: #333;
    /* text-align: center;
    line-height: 160px; */
  }
  a{
    text-decoration: none;
  }
  .el-container{
    height: 750px;
  }
  h1{
  height: 35px;
  text-align: center;
  line-height: 35px;
}

    .el-aside {
    background-color: #D3DCE6;
    color: #333;
    /* text-align: center; */
    /* line-height: 200px; */
    height: 100%;
  }

</style>